home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d1 / biosio3.arc / BIOSIO3.ASM next >
Assembly Source File  |  1988-01-20  |  13KB  |  534 lines

  1. ;              *** biosio.asm ***
  2. ;
  3. ; IBM-PC microsoft "C" under PC-DOS v2.00
  4. ;
  5. ; MICROSOFT "C" callable 8088 assembly routines that interface directly
  6. ; with the basic I/O system (BIOS).
  7. ;
  8. ; NOTE -- The IBM Technical Reference Manual contains a listing of the
  9. ;      BIOS and more complete descriptions of each interrupt.
  10. ;
  11. ; Written by L. Cuthbertson, April 1984
  12. ; Modified for MICROSOFT "C" v3.O  by John Lewis, April 1986
  13. ;**********************************************************************
  14. ;
  15. _TEXT   SEGMENT BYTE PUBLIC 'CODE'
  16.     ASSUME    CS:_TEXT
  17.  
  18.     PUBLIC    _KEYRD,_KEYHIT,_KEYSHIF
  19.  
  20.     PUBLIC    _BIOSINI,_BIOSSET,_BIOSPOS
  21.     PUBLIC    _BIOSUP,_BIOSDN,_BIOSRCA,_BIOSWCA,_BIOSWC
  22.     PUBLIC    _BIOSWD,_BIOSTTY,_BIOSCUR
  23.  
  24.     PUBLIC    _COMINI,_COMOUT,_COMIN,_COMSTAT
  25.  
  26.     PUBLIC    _INP,_OUTP
  27.  
  28. ;
  29. ;**********************************************************************
  30. ;
  31. ;             *** KEYBOARD I/O ***
  32. ;
  33. ; NOTE - Keyboard interrupt description starts on page A-23 of Tech
  34. ;     Ref Manual.
  35. ;
  36. ;**********************************************************************
  37. ;
  38. ; Read a keyboard entry - wait for entry if one not ready.
  39. ;
  40. ; synopsis    c = keyrd();
  41. ;
  42. ;        int c;        high order bits contain scan code
  43. ;                low order bits contain character
  44. ;
  45. ; NOTE - Scan codes are described on page 2-17 of the Technical
  46. ;     Reference Manual.
  47. ;
  48. _KEYRD    PROC    NEAR
  49.     PUSH    BP
  50.     MOV    BP,SP
  51.     MOV    AH,0        ; READ NEXT CHARACTER ENTERED
  52.     INT    16H        ; BIOS KEYBOARD I/O INTERRUPT
  53.     POP    BP
  54.     RET
  55. _KEYRD    ENDP
  56. ;
  57. ; Check to see if there is a character in the keyboard buffer.
  58. ;
  59. ; synopsis    iret = keyhit();
  60. ;
  61. ;        int iret;    = 0 if no character availible
  62. ;                = 1 character is availible
  63. ;
  64. _KEYHIT PROC    NEAR
  65.     PUSH    BP
  66.     MOV    BP,SP
  67.     MOV    AH,1        ; CHECK KEYBOARD BUFFER FUNCTION
  68.     INT    16H        ; BIOS KEYBOARD I/O INTERRUPT
  69.     MOV    AX,0        ; ASSUME THAT NO CHARACTER READY
  70.     JZ    K1
  71.     MOV    AX,1        ; CHARACTER READY
  72. K1:
  73.     POP    BP
  74.     RET
  75. _KEYHIT ENDP
  76. ;
  77. ; Check to see what the shift key status is.
  78. ;
  79. ; synopsis    iret = keyshif();
  80. ;
  81. ;        int iret;    shift key status
  82. ;
  83. ;            0x80 = insert state is active
  84. ;            0x40 = cap lock state has been toggled
  85. ;            0x20 = num lock state has been toggled
  86. ;            0x10 = scroll lock state has been toggled
  87. ;            0x08 = alternate shift key depressed
  88. ;            0x04 = control shift key depressed
  89. ;            0x02 = left shift key depressed
  90. ;            0x01 = right shift key depressed
  91. ;
  92. ; NOTE - from page A-2 and A-3 of Tech Ref Manual
  93. ;
  94. _KEYSHIF PROC    NEAR
  95.     PUSH    BP
  96.     MOV    BP,SP
  97.     MOV    AH,2        ; CHECK SHIFT STATUS FUNCTION
  98.     INT    16H        ; BIOS KEYBOARD I/O INTERRRUPT
  99.     POP    BP
  100.     RET
  101. _KEYSHIF ENDP
  102. ;
  103. ; *********************************************************************
  104. ;
  105. ;            *** VIDEO I/O ***
  106. ;
  107. ; NOTE - the video I/O interrupt description starts on page A-43 of the
  108. ;     Tech Ref Manual.
  109. ;
  110. ; *********************************************************************
  111. ;
  112. ; Initialize screen I/O using the BIOS set mode call
  113. ;
  114. ; synopsis    biosini(stype);
  115. ;
  116. ;        int stype;    screen type
  117. ;
  118. ;            0 = 40x25 BW (power on default)
  119. ;            1 = 40x25 Color
  120. ;            2 = 80x25 BW
  121. ;            3 = 80x25 Color
  122. ;            graphics mode
  123. ;            4 = 320x200 Color
  124. ;            5 = 320x200 BW
  125. ;            6 = 640x200 BW
  126. ;            internal use only
  127. ;            7 = 80x25 BW card
  128. ;
  129. _BIOSINI PROC    NEAR
  130.     PUSH    BP
  131.     MOV    BP,SP
  132.     MOV    AL,[BP+4]    ; SCREEN TYPE IN AL
  133.     MOV    AH,0        ; SET MODE FUNCTION
  134.     INT    10H        ; BIOS VIDEO I/O INTERRUPT
  135.     POP    BP
  136.     RET
  137. _BIOSINI ENDP
  138. ;
  139. ; Set the current cursor position.
  140. ;
  141. ; synopsis    biosset(irow,icol);
  142. ;
  143. ;        *** no value returned ***
  144. ;        int irow;    0 to 24
  145. ;        int icol;    0 to 79
  146. ;
  147. _BIOSSET PROC    NEAR
  148.     PUSH    BP
  149.     MOV    BP,SP
  150.     MOV    DH,[BP+4]    ; ROW
  151.     MOV    DL,[BP+6]    ; COLUMN
  152.     MOV    BH,0        ; CURRENT PAGE NUMBER
  153.     MOV    AH,2        ; CURSOR POSITION SET FUNTION NUMBER
  154.     INT    10H        ; VIDEO I/O INTERRUPT
  155.     POP    BP
  156.     RET
  157. _BIOSSET ENDP
  158. ;
  159. ; Return the current cursor postion.
  160. ;
  161. ; synopsis    iret = biospos();
  162. ;
  163. ;        int iret;    high order bits contain row
  164. ;                low order bits contain column
  165. ;
  166. _BIOSPOS PROC    NEAR
  167.     PUSH    BP
  168.     MOV    BP,SP
  169.     MOV    BH,0        ; CURRENT PAGE NUMBER
  170.     MOV    AH,3        ; CURSOR POSITION FUNCTION NUMBER
  171.     INT    10H        ; VIDEO I/O INTERRUPT
  172.     MOV    AH,DH        ; MOVE INT RETURN INTO FUNCTION RETURN
  173.     MOV    AL,DL        ; DITTO
  174.     POP    BP
  175.     RET
  176. _BIOSPOS ENDP
  177. ;
  178. ; Scroll the screen up within a defined window.
  179. ;
  180. ; synopsis    biosup(numlines,trow,tlcol,brow,brcol,fchar);
  181. ;
  182. ;        int numlines;    number of lines to scroll up
  183. ;        int trow;    top row of window
  184. ;        int tlcol;    top left column of window
  185. ;        int brow;    bottom row of window
  186. ;        int brcol;    bottom right column of window
  187. ;        int fchar;    fill character of opened line
  188. ;
  189. ; note: numlines = 0 blanks entire window.  Upper left corner of full
  190. ;    screen is 0,0 while the bottom right corner of full screen is
  191. ;    24,79.
  192. ;
  193. _BIOSUP PROC    NEAR
  194.     PUSH    BP
  195.     MOV    BP,SP
  196.     MOV    AL,[BP+4]    ; NUMBER OF LINES TO SCROLL
  197.     MOV    CH,[BP+6]    ; TOP ROW OF WINDOW
  198.     MOV    CL,[BP+8]    ; TOP LEFT COLUMN OF WINDOW
  199.     MOV    DH,[BP+10]    ; BOTTOM ROW OF WINDOW
  200.     MOV    DL,[BP+12]    ; BOTTOM RIGHT COLUMN OF WINDOW
  201.     MOV    BH,[BP+14]    ; FILL CHARACTER
  202.     MOV    AH,6        ; SCROLL UP FUNCTION NUMBER
  203.     INT    10H        ; VIDEO I/O INTERRUPT
  204.     POP    BP
  205.     RET
  206. _BIOSUP ENDP
  207. ;
  208. ; Scroll the screen down within a defined window.
  209. ;
  210. ; synopsis    biosdwn(numlines,trow,tlcol,brow,brcol,fchar);
  211. ;
  212. ;        int numlines;    number of lines to scroll down
  213. ;        int trow;    top row of window
  214. ;        int tlcol;    top left column of window
  215. ;        int brow;    bottom row of window
  216. ;        int brcol;    bottom right column of window
  217. ;        int fchar;    fill character of opened line
  218. ;
  219. ; note: numlines = 0 blanks entire window.  Upper left corner of full
  220. ;    screen is 0,0 while the bottom right corner of full screen is
  221. ;    24,79.
  222. ;
  223. _BIOSDN PROC    NEAR
  224.     PUSH    BP
  225.     MOV    BP,SP
  226.     MOV    AL,[BP+4]    ; NUMBER OF LINES TO SCROLL
  227.     MOV    CH,[BP+6]    ; TOP ROW OF WINDOW
  228.     MOV    CL,[BP+8]    ; TOP LEFT COLUMN OF WINDOW
  229.     MOV    DH,[BP+10]    ; BOTTOM ROW OF WINDOW
  230.     MOV    DL,[BP+12]    ; BOTTOM RIGHT COLUMN OF WINDOW
  231.     MOV    BH,[BP+14]    ; FILL CHARACTER
  232.     MOV    AH,7        ; SCROLL DOWN FUNCTION NUMBER
  233.     INT    10H        ; VIDEO I/O INTERRUPT
  234.     POP    BP
  235.     RET
  236. _BIOSDN ENDP
  237. ;
  238. ; Read the contents of a given screen cell.
  239. ;
  240. ; synopsis    iret=biosrca();
  241. ;
  242. ;        int iret;    high order bits contain attributes
  243. ;                low order bits contain character
  244. ;
  245. ; NOTE - Attributes are defined on page 13-9 of the DOS v2.0 manual
  246. ;
  247. _BIOSRCA PROC    NEAR
  248.     PUSH    BP
  249.     MOV    BP,SP
  250.     MOV    BH,0        ; ACTIVE DISPLAY PAGE
  251.     MOV    AH,8        ; READ CHARACTER + ATTRIBUTES FUNCTION
  252.     INT    10H        ; VIDEO I/O INTERRUPT
  253.     POP    BP
  254.     RET
  255. _BIOSRCA ENDP
  256. ;
  257. ; Write a character to the screen - with attributes.
  258. ;
  259. ; synopsis    bioswca(char,count,att);
  260. ;
  261. ;        *** no value returned ***
  262. ;        int char;    character to output
  263. ;        int count;    number of times to output character
  264. ;        int att;    character attribute
  265. ;
  266. ; NOTE - Attributes are defined on page 13-9 of the DOS v2.0 manual
  267. ;
  268. _BIOSWCA PROC    NEAR
  269.     PUSH    BP
  270.     MOV    BP,SP
  271.     MOV    AL,[BP+4]    ; CHARACTER
  272.     MOV    CX,[BP+6]    ; NUMBER OF CHARACTERS TO WRITE
  273.     MOV    BL,[BP+8]    ; CHARACTER ATTRIBUTE
  274.     MOV    BH,0        ; ACTIVE DISPLAY PAGE
  275.     MOV    AH,9        ; WRITE CHARACTER/w ATTRIBUTES FUNCTION
  276.     INT    10H        ; VIDEO I/O INTERRUPT
  277.     POP    BP
  278.     RET
  279. _BIOSWCA ENDP
  280. ;
  281. ; Write a character to the screen - no attributes.
  282. ;
  283. ; synopsis    bioswc(char,count);
  284. ;
  285. ;        *** no value returned ***
  286. ;        int char;    character to output
  287. ;        int count;    number of times to output character
  288. ;
  289. _BIOSWC PROC    NEAR
  290.     PUSH    BP
  291.     MOV    BP,SP
  292.     MOV    AL,[BP+4]    ; CHARACTER
  293.     MOV    CX,[BP+6]    ; NUMBER OF CHARACTERS TO WRITE
  294.     MOV    BL,0;        ; CHARACTER ATTRIBUTE - NULL
  295.     MOV    BH,0        ; ACTIVE DISPLAY PAGE
  296.     MOV    AH,10        ; WRITE CHARACTER ONLY FUNCTION NUMBER
  297.     INT    10H        ; VIDEO I/O INTERRUPT
  298.     POP    BP
  299.     RET
  300. _BIOSWC ENDP
  301. ;
  302. ; Write a dot in graphics mode.
  303. ;
  304. ; synopsis    bioswd(irow,icol);
  305. ;
  306. ;        *** no value returned ***
  307. ;        int irow;
  308. ;        int icol;
  309. ;
  310. _BIOSWD PROC    NEAR
  311.     PUSH    BP
  312.     MOV    BP,SP
  313.     MOV    DX,[BP+4]    ; ROW
  314.     MOV    CX,[BP+6]    ; COLUMN
  315.     MOV    AL,1        ; GREEN COLOR
  316.     MOV    AH,12        ; WRITE A DOT FUNCTION NUMBER
  317.     INT    10H        ; VIDEO I/O INTERRUPT
  318.     POP    BP
  319.     RET
  320. _BIOSWD ENDP
  321. ;
  322. ; Write a character to the screen using the BIOS ascii teletype call.
  323. ; The teletype call will send cr/lf if column 79 is written to (0-79).
  324. ; It will scroll the screen up if row 24 (0-24) column 79 is written to.
  325. ; It will also beep the bell if ^g is received and provide a destructive
  326. ; backspace.
  327. ;
  328. ; synopsis    biostty(c);
  329. ;
  330. ;        char c;     character to write.
  331. ;
  332. _BIOSTTY PROC    NEAR
  333.     PUSH    BP
  334.     MOV    BP,SP
  335.     MOV    AL,[BP+4]    ; CHARACTER TO WRITE INTO AL
  336.     MOV    AH,14        ; TTY FUNCTION
  337.     MOV    BH,0        ; DISPLAY PAGE
  338.     INT    10H        ; BIOS VIDEO I/O INTERRUPT
  339.     POP    BP
  340.     RET
  341. _BIOSTTY ENDP
  342. ;
  343. ; Return the current video state of the screen.
  344. ;
  345. ; synopsis    iret = bioscur();
  346. ;
  347. ;        int iret;    low bits are the mode currently set
  348. ;                (see biosini for description)
  349. ;                high bits are the number of columns on screen
  350. ;
  351. _BIOSCUR PROC    NEAR
  352.     PUSH    BP
  353.     MOV    BP,SP
  354.     MOV    AH,15        ; CURRENT VIDEO STATE FUNCTION
  355.     INT    10H        ; BIOS VIDEO I/O INTERRUPT
  356.     POP    BP
  357.     RET
  358. _BIOSCUR ENDP
  359. ;
  360. ; *******************************************************************
  361. ;
  362. ;            *** communications port ***
  363. ;
  364. ; NOTE - the communications port I/O is described starting on page A-20
  365. ;     of the Tech Ref Manual.
  366. ;
  367. ; *******************************************************************
  368. ;
  369. ; Initialize the communications port.
  370. ;
  371. ; synopsis    iret = comini(port,params);
  372. ;
  373. ;        int iret;    return status (see comstat)
  374. ;        int port;    communications port to initialize (0,1)
  375. ;        int params;    bit pattern for initialization -
  376. ;
  377. ;    7    6    5    4    3    2    1    0
  378. ;    ------BAUD RATE ---    --PARITY--   STOP BIT    --WORD LENGTH--
  379. ;
  380. ;    000 - 110        X0 - NONE    0 - 1    10 - 7 BITS
  381. ;    001 - 150        01 - ODD    1 - 2    11 - 8 BITS
  382. ;    010 - 300        11 - EVEN
  383. ;    011 - 600
  384. ;    100 - 1200
  385. ;    101 - 2400
  386. ;    110 - 4800
  387. ;    111 - 9600
  388. ;
  389. _COMINI PROC    NEAR
  390.     PUSH    BP
  391.     MOV    BP,SP
  392.     MOV    DX,[BP+4]    ; _COMM PORT TO INITIALIZE
  393.     MOV    AL,[BP+6]    ; PARAMETERS
  394.     MOV    AH,0        ; INITIALIZATION FUNCTION
  395.     INT    14H        ; _COMM PORT I/O INTERRUPT
  396.     POP    BP
  397.     RET
  398. _COMINI ENDP
  399. ;
  400. ; Write a character to the communications port.
  401. ;
  402. ; synopsis    iret = comout(port,c);
  403. ;
  404. ;        int iret;    error return ( >127 if error occured)
  405. ;                - see AH under modem control
  406. ;        int port;    communications port to write (0 or 1)
  407. ;        int c;        character to write.
  408. ;
  409. _COMOUT PROC    NEAR
  410.     PUSH    BP
  411.     MOV    BP,SP
  412.     MOV    DX,[BP+4]    ; _COMM PORT TO WRITE
  413.     MOV    AL,[BP+6]    ; CHARACTER TO WRITE
  414.     MOV    AH,1        ; WRITE CHARACTER FUNCTION
  415.     INT    14H        ; _COMM PORT I/O INTERRUPT
  416.     POP    BP
  417.     RET
  418. _COMOUT ENDP
  419. ;
  420. ; Read a character from the communications port.  Waits for character if
  421. ; one is not ready.  See \comm\ibmtty.c for example of polling comm port
  422. ; for character without wait.
  423. ;
  424. ; synopsis    c = comin(port);
  425. ;
  426. ;        int c;        character read from comm port,
  427. ;                > 127 if error or no character ready.
  428. ;                - see AH under modem control
  429. ;        int port;    communications port to read (0 or 1)
  430. ;
  431. _COMIN    PROC    NEAR
  432.     PUSH    BP
  433.     MOV    BP,SP
  434.     MOV    DX,[BP+4]    ; _COMM PORT TO READ
  435.     MOV    AH,2        ; READ CHARACTER FUNCTION
  436.     INT    14H        ; _COMM PORT I/O INTERRUPT
  437.     POP    BP
  438.     RET
  439. _COMIN    ENDP
  440. ;
  441. ; Check the line and modem status
  442. ;
  443. ; synopsis    iret = comstat(port);
  444. ;
  445. ;        int iret;    ; line and modem status
  446. ;        AH - high order bits contain line control status
  447. ;        bit 7 = time out
  448. ;        bit 6 = trans shift register empty
  449. ;        bit 5 = trans holding register empty
  450. ;        bit 4 = break detect
  451. ;        bit 3 = framing error
  452. ;        bit 2 = parity error
  453. ;        bit 1 = overrun error
  454. ;        bit 0 = data ready
  455. ;
  456. ;        AL - low order bits contain modem status
  457. ;        bit 7 = received line signal detect
  458. ;        bit 6 = ring indicator
  459. ;        bit 5 = data set ready
  460. ;        bit 4 = clear to send
  461. ;        bit 3 = delta receive line signal detect
  462. ;        bit 2 = trailing edge ring detector
  463. ;        bit 1 = delta data set ready
  464. ;        bit 0 = delta clear to send
  465. ;
  466. ; Note - from page A-21 of Tech Ref Manual
  467. ;
  468. ;        int port;    ; communications port to check
  469. ;
  470. _COMSTAT PROC    NEAR
  471.     PUSH    BP
  472.     MOV    BP,SP
  473.     MOV    DX,[BP+4]    ; _COMM PORT TO CHECK
  474.     MOV    AH,3        ; STATUS FUNCTION
  475.     INT    14H        ; _COMM PORT I/O INTERRUPT
  476.     POP    BP
  477.     RET
  478. _COMSTAT ENDP
  479. ;
  480. ;**********************************************************************
  481. ;
  482. ;            *** io.asm ***
  483. ;
  484. ; IBM-PC 8088 assembly for interface with microsoft "C" under PC-DOS
  485. ;
  486. ; "C" callable subroutines that provide absolute pointer addressing.
  487. ; Pointers within a IBM-PC microsoft "C" program are relative to the
  488. ; start of the programs data segment.  These subroutines provide a
  489. ; mechanism to address absolute memory locations.
  490. ;
  491. ; Supplied by microsoft - commented by L. Cuthbertson, April 1984
  492. ;
  493. ;**********************************************************************
  494. ;
  495. ; Read an absolute memory location.
  496. ;
  497. ; synopsis    c = readabs(loc);
  498. ;
  499. ;        int c;        contents of memory location
  500. ;        int loc;    absolute memory location in hex
  501. ;
  502. _INP    PROC    NEAR
  503.     PUSH    BP
  504.     MOV    BP,SP
  505.     MOV    DX,[BP+4]    ;GET LOCATION ADDRESS
  506.     IN    AL,DX        ;READ LOCATION
  507.     XOR    AH,AH        ;CLEAR HIGH BYTE
  508.     POP    BP
  509.     RET
  510. _INP    ENDP
  511. ;
  512. ; Write an absolute memory location.
  513. ;
  514. ; synopsis    writeabs(loc,c);
  515. ;
  516. ;        int loc;    absolute memory location in hex
  517. ;        int c;        integer to write to memory location
  518. ;
  519. _OUTP    PROC    NEAR
  520.     PUSH    BP
  521.     MOV    BP,SP
  522.     MOV    DX,[BP+4]    ;GET LOCATION ADDRESS
  523.     MOV    AX,[BP+6]    ;GET ADDRESS OF INTEGER TO WRITE
  524.     OUT    DX,AL        ;WRITE TO MEMORY LOCATION
  525.     POP    BP
  526.     RET
  527. _OUTP    ENDP
  528. ;
  529. ;**********************************************************************
  530.  
  531. _TEXT    ENDS
  532.     END
  533. ;
  534.